# Copyright 2018- The Pixie Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("//bazel:pl_build_system.bzl", "pl_go_test")

go_library(
    name = "server",
    srcs = [
        "grpc_server.go",
        "server.go",
    ],
    importpath = "px.dev/pixie/src/shared/services/server",
    visibility = ["//src:__subpackages__"],
    deps = [
        "//src/shared/services",
        "//src/shared/services/authcontext",
        "//src/shared/services/env",
        "@com_github_grpc_ecosystem_go_grpc_middleware//:go-grpc-middleware",
        "@com_github_grpc_ecosystem_go_grpc_middleware//auth",
        "@com_github_grpc_ecosystem_go_grpc_middleware//logging/logrus",
        "@com_github_grpc_ecosystem_go_grpc_middleware//tags",
        "@com_github_sirupsen_logrus//:logrus",
        "@com_github_spf13_viper//:viper",
        "@org_golang_google_grpc//:grpc",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//encoding/gzip",
        "@org_golang_google_grpc//reflection",
        "@org_golang_google_grpc//status",
        "@org_golang_x_net//http2",
        "@org_golang_x_net//http2/h2c",
    ],
)

pl_go_test(
    name = "server_test",
    srcs = ["grpc_server_test.go"],
    deps = [
        ":server",
        "//src/shared/services/env",
        "//src/shared/services/testproto:ping_pl_go_proto",
        "//src/utils/testingutils",
        "@com_github_spf13_viper//:viper",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@org_golang_google_grpc//:grpc",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//credentials/insecure",
        "@org_golang_google_grpc//metadata",
        "@org_golang_google_grpc//status",
        "@org_golang_google_grpc//test/bufconn",
        "@org_golang_x_sync//errgroup",
    ],
)
